package com.weiqiao.mall.repository.impl;

import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IPageDecorationRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("PageDecorationRepositoryImpl")
public class PageDecorationRepositoryImpl extends BaseMongoDaoImpl implements IPageDecorationRepository {

    private String PAGE_DECORATION = "page_decoration";

    private static final String PAGE_DECORATION_DETAIL = "page_decoration_detail";

    @Override
    public List<String> findAll(Bson filter, Bson sort, int page, int size) {
        if (page == 0) {
            page = 1;
        }
        // 获取起始条数
        int skip = (page - 1) * size;
        List<String> string = super.findFilterSortSkipLimit(PAGE_DECORATION, filter, sort, skip, size);
        return string;
    }

    @Override
    public String findOne(Bson filter) {
        return super.findOne(PAGE_DECORATION, filter);
    }

    @Override
    public boolean updateOne(Bson filter, String json) {
        return super.updateOne(PAGE_DECORATION, filter, json, true);
    }

    @Override
    public List<String> findAll(Bson filter) {
        return super.findFilter(PAGE_DECORATION, filter);
    }

    /**
     * 根据条件查询页面装修首页数据
     *
     * @param filter
     * @return
     */
    @Override
    public List<String> getPageDecorationList(Bson filter, Pageable pageable) {
        return super.getListAndPage(PAGE_DECORATION, filter, pageable);
    }

    /**
     * 根据条件查询装修页详情列表
     *
     * @param filter
     * @return
     */
    @Override
    public List<String> getPageDecorationDetailList(Bson filter) {
        return super.findFilter(PAGE_DECORATION_DETAIL, filter);
    }

    /**
     * 根据条件查询并更新
     *
     * @param filter
     * @param document
     * @param bool
     * @return
     */
    @Override
    public boolean findAndUpdate(Bson filter, Document document, boolean bool) {
        return super.updateOne(PAGE_DECORATION_DETAIL, filter, document, bool);
    }

    /**
     * 删除页面装修详情数据
     *
     * @param filter
     * @return
     */
    @Override
    public boolean del(Bson filter) {
        return super.delMany(PAGE_DECORATION_DETAIL, filter);
    }

    /**
     * 根据条件查询装修详情页数据
     *
     * @param filter
     * @return
     */
    @Override
    public String getPageDecorationDetail(Bson filter) {
        return super.findOne(PAGE_DECORATION_DETAIL, filter);
    }

    @Override
    public int countNum(Bson filter) {
        return super.statististics(PAGE_DECORATION, filter);
    }
}
